package com.game.model;

import com.game.global.Const;
import com.game.global.CrashType;
import com.game.interfaces.CollisionAble;
import com.game.interfaces.LifeCycle;
import com.game.main.GameContext;
import com.game.util.ImageUtil;
import com.game.util.PropertiesUtil;

import java.awt.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by tjc on 2019-3-21.
 *
 * @auther: tjc
 * @Date: 2019-3-21
 */
public class Wall extends Module implements CollisionAble, LifeCycle {

    public Wall(){
        SIZE_X = PropertiesUtil.loadInt("wall.width");
        SIZE_Y = PropertiesUtil.loadInt("wall.length");
        direction = Const.DIRECTION_UP;
    }

    private AtomicBoolean alive = new AtomicBoolean(false);

    public Rectangle getRec() {
        return new Rectangle(localX, localY, SIZE_X, SIZE_Y);
    }

    @Override
    public int getCollisionType() {
        return CrashType.WALL;
    }


    public void draw(Graphics g) {
        g.drawImage(ImageUtil.wallImages[0], localX, localY, SIZE_X, SIZE_Y, null);
    }

    public int getLocalX() {
        return localX;
    }

    public void setLocalX(int localX) {
        this.localX = localX;
    }

    public int getLocalY() {
        return localY;
    }

    public void setLocalY(int localY) {
        this.localY = localY;
    }

    public int getBottom() {
        return this.getLocalY() + SIZE_Y;
    }

    public int getRight() {
        return this.getLocalX() + SIZE_X;
    }

    @Override
    public void init() {
        alive.set(true);
    }

    @Override
    public void destroy() {
        alive.set(false);
    }

    @Override
    public boolean alive() {
        return alive.get();
    }
}
